<!doctype html>
<html>
    <head>
        <meta charset="UTF-8"/>
        <title>商场问题</title>
	    <link rel="stylesheet" type="text/css" href="/webapp/css/easyui.css">
	    <link rel="stylesheet" type="text/css" href="/webapp/css/icon.css">
        <link rel="stylesheet" type="text/css" href="/webapp/css/color.css">
        <link rel="stylesheet" type="text/css" href="/webapp/css/public.css">
	    <script type="text/javascript" src="/webapp/js/lib/jquery.min.js"></script>
	    <script type="text/javascript" src="/webapp/js/lib/jquery.easyui.min.js"></script>
	    <script type="text/javascript" src="/webapp/js/lib/ajaxfileupload.js"></script>
	    <script type="text/javascript" src="/webapp/js/common/config.js"></script>
    </head>
    <body>
       <div class="easyui-container-fluid">
          <div class="easyui-panel" style="border: none;">
            <div class="nav" id="nav"></div> 
            <div class="easyui-panel" style="border:none;">
               <form id="ff">
               <div style="margin-bottom:20px;">
                     <label class="item-label">年份：</label>
                     <input type="text" class="easyui-combobox" name="year" id="year" style="width:100px;"/>
                 	<span id="monthLabel">
                      <label class="item-label">月份：</label>
                      <input type="text" class="easyui-combobox" name="month" id="month" style="width:100px;"/>
                 	</span>
                 	<span id="weekLabel">
                      <label class="item-label">周数：</label>
                      <input type="text" class="easyui-combobox" name="week" id="week" style="width:100px;"/>
                 	</span>
                 	<label class="item-label">问题类型：</label>
                    <select name="type" class="easyui-combobox" style="width:100px;" data-options="panelHeight:'100'">
	                    <option value="">-请选择-</option>
	                    <option value="BRAND_MISS">品牌缺失</option>
	                    <option value="BRAND_REPEAT">品牌重复</option>
                  	</select>
                     <label class="item-label">渠道：</label>
                     <input type="text" class="easyui-textbox" name="channelName"  style="width:100px;"/>
                     <label class="item-label">提问人：</label>
                     <input type="text" class="easyui-textbox" name="submitUserName"  style="width:100px;"/>
                 </div>
                <div style="margin-bottom:20px;">
                  <label class="item-label">品类：</label>
		          <select id="categorySelect" name="categoryCode" class="easyui-combobox" style="width:100px;"></select> 
                  <label class="item-label">处理状态：</label>
                  <select name="status" class="easyui-combobox" style="width:100px;" data-options="panelHeight:'100'">
                    <option value="">-请选择-</option>
                    <option value="WAITTING">未处理</option>
                    <option value="FINISHED">已处理</option>
                  </select>
                  <label class="item-label">商场：</label>
                  <input type="text" class="easyui-textbox" name="mallName"  style="width:100px;"/>
                  
                  <a href="javascript:void(0);" style="margin-left:15px;width:80px;" class="easyui-linkbutton" onclick="searchBy()">查询</a>
                </div>
              </form>
            </div>
            <div class="table-wrapper">
             <table id="datagrid" class="easyui-datagrid" data-options="fitColumns:true,scrollbarSize:0,toolbar:'#cusToolbar'">
               <thead>
                 <tr>
                   <th field="ck" checkbox="true"></th>
                   <th data-options="field:'status',align:'center'" width="100">状态</th>
                   <th data-options="field:'code',align:'center'" width="100" formatter="nameFormat">编号</th>
                   <th data-options="field:'replyUserName',align:'center'" width="100">回复人</th>
                   <th data-options="field:'replyTime',align:'center'" width="160">回复时间</th>
                   <th data-options="field:'reply',align:'center'" width="250">回复内容</th>
                   <th data-options="field:'categoryName',align:'center'" width="100" formatter="internationalFormat">品类</th>
                   <th data-options="field:'type',align:'center',formatter:boolFormatter" width="100">问题类型</th>
                   <th data-options="field:'channelName',align:'center',formatter:statusFormatter" width="100">渠道</th>
                   <th data-options="field:'mallName',align:'center',formatter:statusFormatter" width="100">商场</th>
                   <th data-options="field:'brandName',align:'center',formatter:statusFormatter" width="100">品牌</th>
                   <th data-options="field:'modelName',align:'center',formatter:statusFormatter" width="100">型号</th>
                   <th data-options="field:'question',align:'center',formatter:statusFormatter" width="100">问题描述</th>
                   <th data-options="field:'remark',align:'center',formatter:statusFormatter" width="100">备注</th>
                 </tr>
               </thead>
               <tbody>
               </tbody>
             </table>
           </div>
          </div> 
       </div>
       
       <div id="cusToolbar" style="padding:5px;height:auto">
		<div style="margin-bottom:5px">
			<a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="showSmartReply();">详细回复</a>
			快捷操作：
			<select class="easyui-combobox" panelHeight="auto" style="width:200px" id="replyCombobox">
				<option value="无销售">无销售</option>
				<option value="销量无误">销量无误</option>
				<option value="有促销活动故销量较大">有促销活动故销量较大</option>
				<option value="包含部分批发或团购">包含部分批发或团购</option>
				<option value="全部为批发或团购">全部为批发或团购</option>
				<option value="数据有误请删除">数据有误请删除</option>
				<option value="无效">无效</option>
			</select>
			<a href="#" class="easyui-linkbutton" onclick="quickReply();">确定</a>
		</div>
	</div>
	
	<div id="replyDialog" class="easyui-dialog" title="详细回复" style="width:600px;height:300px;" closed="true"
	    data-options="resizable:false,modal:true,buttons:'#rbtn'">
	    <div style="margin-bottom:20px;">
   			<input type="text" class="easyui-textbox" name="remark" multiline="true" style="width:570px;height:195px;"/>
   		</div>
   		<div id="rbtn" style="text-align: center;">
			<a href="#" class="easyui-linkbutton" onclick="smartReply();">回复</a>
			<a href="#" class="easyui-linkbutton" onclick="closeDialog();">关闭</a>
		</div>
	</div>
    </body>
    <script type="text/javascript">
           $(function(){
               setNav();
               initCategorySelect("categorySelect");
               if(isMonthType()){
                   // 月报
                   $('#weekLabel').remove();
                   initMonthSelect("month");
               }else{
                   // 周报
                   initWeekSelect("week");
                   $('#monthLabel').remove();
               }
               initYearSelect("year");
               pageLoad();
               $("#datagrid").datagrid({
                   pagination:true,
                   rownumbers:true,
                   checkOnSelect:true,
                   selectOnCheck:true
               });
               searchBy();

           });
           function showSmartReply(){
        	   $('#replyDialog').dialog({
        		    title: '详细回复',
        		    closed: false,
        		    cache: false,
        		    modal: true
        		});
           }
           function closeDialog(){
        	   $("#replyDialog").dialog("close");
           }
           function smartReply(){
        	   
           }
           function quickReply(){
        	   var reply = $('#replyCombobox').combobox('getValue');
        	   if(!reply){
        	 		alert('请选择回复内容');
        	   }
        	 	//获取选中的所有行数据
        	   var rows = $('#datagrid').datagrid('getSelections');
        	 	if(!rows || rows.length<=0){
        	 		alert('请先选择要回复的问题');
        	 	}
        	 	var idList = [];
        	 	for(var i=0;i<rows.length;i++){
        	 		idList.push(rows[i]['id']);
        	 	}
        	   return;
              $.messager.confirm("提示","确定回复吗？",function(flag){
                 if(flag){
                    $.ajax({
                        url:config.url+"/question/reply",
                        type:'PATCH',
                        data:{'reply': reply, 'idList': idList},
                        dataType:'json',
                        contentType:'application/json;charset=UTF-8',
                        xhrFields:{withCredentials:true},
                        success:function(data){
                            $.messager.alert("提示","回复成功");
                            searchBy();
                        },
                        error:function(XMLHttpRequest,textStatus,thrown){
                            $.messager.alert("提示","回复失败","error");
                        }
                    });
                 }
            });
           }
           
           function pageLoad(){
          	 var data = getFormData(document.getElementById("ff"));
          	 data['page'] = 1;
          	 data['size'] = 10;
          	 $.ajax({
                   url:config.url + "/question",
                   type:"get",
                   data: transfer(data),
                   xhrFields:{withCredentials:true},
                   beforeSend:function () {
                     $.messager.progress({
                         title:"请稍等",
                         interval:50,
                         text:"数据加载中..."
                     });
                   },
                   complete:function () {
                     $.messager.progress("close");
                   },
                   success:function(data){
                      $("#datagrid").datagrid("loadData",{total:data.totalElements,rows:data.content}).datagrid("getPager").pagination({
                          pageList:[10,15,20,25,30,35,40,50,100],
                          displayMsg:"共{total}条记录",
                          total:data.totalElements,
                          onSelectPage:function (page,size) {
                          	searchBy(page, size);
                          }
                      });
                      $.messager.progress("close");
                   },
                   error:function(data){
                      console.log(data);
                       $.messager.progress("close");
                   }
               });
          	 
           }
           
           function searchBy(page, size){
          	 var data = getFormData(document.getElementById("ff"));
          	 data['page'] = !!page?page:1;
          	 data['size'] = !!size?size:10;
               $.ajax({
                    url:config.url + "/question",
                    type:"get",
                    data:transfer(data),
                    xhrFields:{withCredentials:true},
                    beforeSend:function () {
                        $.messager.progress({
                            title:"请稍等",
                            interval:50,
                            text:"数据加载中..."
                        });
                      },
                    success:function(data){
                       $("#datagrid").datagrid("loadData",{total:data.totalElements,rows:data.content}).datagrid("getPager").pagination({
                           pageList:[10,15,20,25,30,35,40,50,100],
                           displayMsg:"共{total}条记录",
                           total:data.totalElements
                       });
                       $.messager.progress("close");
                    },
                    error:function(data){
                       console.log(data);
                       $.messager.progress("close");
                    }
                });
           }
           	function internationalFormat(val, row) {
            	return 'DOMESTIC'==val?'是':'否';
   			}
           	function nameFormat(val, row) {
           		if(row.parentBrandName){
           			return val + '(' + row.parentBrandName + ')';
           		}else{
           			return val;
           		}
   			}
      </script>
</html>
